<template>
  <div class="container">
    <p class="logo">xxxx开放平台</p>
    <p class="copyright">Copyright © 2023 xxxx 版权所有</p>
    <div class="box">
      <div class="card">
        <div class="boxLeft"></div>
        <div class="boxRight">
          <p class="title">账号密码登录</p>
          <a-form
            class="form"
            layout="vertical"
            :model="formState"
            name="basic"
            autocomplete="off"
            @finish="onFinish"
            @finishFailed="onFinishFailed"
          >
            <a-form-item label="" name="userName" :rules="[{ required: true, message: '请输入用户名' }]">
              <a-input placeholder="请输入用户名" autocomplete="false" v-model:value="formState.userName" />
            </a-form-item>
            <a-form-item label="" name="password" :rules="[{ required: true, message: '请输入密码' }]">
              <a-input
                placeholder="请输入密码"
                autocomplete="false"
                type="password"
                v-model:value="formState.password"
              />
            </a-form-item>
            <a-form-item>
              <a-button class="submitBtn" type="primary" html-type="submit" :loading="loading">登 录</a-button>
            </a-form-item>
          </a-form>
        </div>
      </div>
    </div>
  </div>
</template>
~

<script setup name="login">
  import { ACCESS_TOKEN, HOME_PAGE_PATH } from '@/mutation-type';
  import { webStorage } from '@/utils/webStorage';
  import { useUserStore } from '@/store/user';
  import router from '@/router';
  import { ref, reactive } from 'vue';

  const formState = reactive({
    userName: 'admin',
    password: '123456'
  });
  const loading = ref(false);
  const onFinish = values => {
    console.log('Success:', values);
    authLogin(values);
  };
  const onFinishFailed = errorInfo => {
    console.log('Failed:', errorInfo);
  };

  const authLogin = data => {
    let user = useUserStore();
    let userInfo = data;
    user.setUser(userInfo);
    webStorage.ls.set(ACCESS_TOKEN, userInfo, 2 * 24 * 60 * 60 * 1000);
    router.push(HOME_PAGE_PATH);
  };
</script>

<style lang="less" scoped>
  .container {
    height: 100%;
    position: relative;
    background: url(@/assets/image/user/login-bg.png) no-repeat center center/cover;
  }
  .logo {
    position: absolute;
    top: 40px;
    left: 40px;
    font-size: 30px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 0 2px rgb(66 65 65);
  }
  .copyright {
    position: absolute;
    border-top: 1px solid rgba(255, 255, 255, 0.6);
    font-size: 12px;
    color: var(--text-color);
    height: 40px;
    line-height: 40px;
    bottom: 0;
    left: 0;
    width: 100%;
    text-align: center;
  }
  .box {
    width: 640px;
    height: 480px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    &::before {
      position: absolute;
      bottom: -15px;
      left: 50%;
      transform: translate(-50%, 0);
      content: '';
      width: 610px;
      height: 15px;
      opacity: 0.6;
      background: #ffffff;
      border-bottom-left-radius: 6px;
      border-bottom-right-radius: 6px;
      z-index: 2;
    }
    &::after {
      position: absolute;
      bottom: -30px;
      left: 50%;
      transform: translate(-50%, 0);
      content: '';
      width: 580px;
      height: 15px;
      opacity: 0.4;
      background: #ffffff;
      z-index: 1;
      border-bottom-left-radius: 6px;
      border-bottom-right-radius: 6px;
    }
  }
  .card {
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid #ffffff;
    box-shadow: 0 4px 10px 0 #e2f6ff;
    border-radius: 6px;
    height: 100%;
    height: 100%;
    position: relative;
    padding: 40px;
    display: flex;
    justify-content: space-between;
    z-index: 3;
    &::before {
      position: absolute;
      left: 0;
      bottom: 0;
      content: '';
      width: 640px;
      height: 114px;
      background-image: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #eefbff 100%);
      border-radius: 6px;
    }
  }
  .boxLeft {
    background: url(@/assets/image/user/login-pic01.png) no-repeat center center/160px 400px;
    height: 400px;
    width: 160px;
    margin-right: 40px;
  }
  .boxRight {
    flex: 1;
    position: relative;
    .title {
      padding-top: 10px;
      line-height: 37px;
      font-size: 26px;
      color: var(--heading-color);
      position: relative;
      margin-bottom: 70px;
      &::before {
        content: '';
        position: absolute;
        width: 60px;
        height: 3px;
        left: 0;
        bottom: -14px;
        background-image: linear-gradient(130deg, #3ee5d0 0%, #07bfa8 100%);
        box-shadow: 0 4px 11px 0 #81bdb5;
      }
    }
  }
  .form {
    .ant-form-item {
      position: relative;
      height: 40px;
      margin-bottom: 30px;
      &:last-child {
        margin-bottom: 0;
        margin-top: 60px;
      }
    }
    :deep(.ant-form-item-control-input) {
      min-height: 40px;
    }
    .ant-form-item-has-success {
      input {
        border-color: var(--primary-color);
      }
    }
    input {
      height: 40px;
      line-height: 40px;
      padding: 0 10px;
      border: 0;
      border-bottom: 1px solid #d8d8d8;
      background: transparent;
      border-radius: 0;
      color: #000;
      font-size: 14px;
      transition: border-color 300ms ease;
      box-shadow: none !important;
      background-color: transparent !important;
      &:focus,
      &:hover {
        box-shadow: none;
        background: none;
      }
      &:placeholder {
        color: #999;
      }
      &:-webkit-autofill {
        font-size: 14px;
        -webkit-text-fill-color: #000;
        -webkit-box-shadow: 0 0 0px 1000px transparent inset !important;
        background-color: transparent;
        background-image: none;
        transition: background-color 50000s ease-in-out 0s;
      }
    }
    .submitBtn {
      height: 40px;
      display: block;
      width: 100%;
      font-size: 18px;
    }
  }
</style>
